package com.sun.dao.role;

import com.sun.dao.BaseDao;
import com.sun.pojo.Role;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author SunBingRui
 * @Date 2020/4/29 20:32
 */
public class RoleDaoImpl implements RoleDao {

        //获取角色列表，不需要分页
        public List<Role> getRoleList (Connection connection) throws SQLException {

            PreparedStatement pre = null;
            ResultSet rs = null;
            List<Role> roleList = new ArrayList<Role>();

            if(connection!=null){
                String sql = "select * from smbms_role";
                Object[] params = {};//没有参数

                rs = BaseDao.execute(connection, pre, rs,sql, params);

                while (rs.next()){
                    Role role = new Role();

                    role.setId(rs.getInt("id"));
                    role.setRoleCode(rs.getString("roleCode"));
                    role.setRoleName(rs.getString("roleName"));
                    role.setCreatedBy(rs.getInt("createdBy"));
                    role.setCreationDate(rs.getTimestamp("creationDate"));
                    role.setModifyBy(rs.getInt("modifyBy"));
                    role.setModifyDate(rs.getTimestamp("modifyDate"));

                    roleList.add(role);
                }

                BaseDao.closeResource(null, pre, rs);
            }

            return roleList;
        }



}




